package com.talentgame.tankspk.GameCore;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.collision.Collision;
import com.badlogic.gdx.physics.bullet.collision.ContactCallbackEvent;
import com.badlogic.gdx.physics.bullet.collision.btCollisionObject;
import com.badlogic.gdx.physics.bullet.dynamics.btRigidBody;

/**
 * Created by 54560 on 2016/12/26.
 * 子弹类
 */
public class TankBullet extends GameObject{
    public float speed = 10;
    //发出这个子弹的玩家
    public int playerid;
    public TankBullet(Model model) {
        super(model);
    }

    public TankBullet(Model model, String nodeId,int playerid) {
        super(model, nodeId);
        this.playerid = playerid;
        body.setCollisionFlags(body.getCollisionFlags() |btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK );
        body.setContactCallbackFlag(TanksGame.OBJECT_FLAG);
        body.setContactCallbackFilter( TanksGame.OBJECT_FLAG);
        body.setActivationState(Collision.DISABLE_DEACTIVATION);
        //body.setGravity(new Vector3(0,0,0));
        //body.applyGravity();

        //transform.trn(0,0,0.2f);
    }
    float timer = 0;
    @Override
    public void update(float detalTime) {
        super.update(detalTime);
        body.setGravity(new Vector3(0,0,0));
        //Gdx.app.log("G",body.getGravity().toString());
        Vector3 forward = getForward(transform);
        transform.trn(forward.scl(speed*detalTime));
        body.proceedToTransform(transform);
        timer += detalTime;
        if(timer > 3)
        {

            Gdx.app.log("销毁","销毁:" + uniqueId);
            TanksGame.instance.collisionWorld.removeRigidBody(body);
            TanksGame.instance.renderList.remove(uniqueId);
            dispose();
        }
    }

    @Override
    protected btRigidBody.btRigidBodyConstructionInfo getConstructionInfo() {
        SetMass(1);
        return super.getConstructionInfo();
    }
}
